﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Sizebox.CharacterEditor
{
	// Token: 0x0200024E RID: 590
	public class MaterialDetailTextureOption : MaterialControlOption
	{
		// Token: 0x06000CD0 RID: 3280 RVA: 0x00067698 File Offset: 0x00065898
		private void Awake()
		{
			this.PrepareDetailMapDropdown();
			this.xScale.onValueChanged.AddListener(new UnityAction<string>(this.OnXScale));
			this.yScale.onValueChanged.AddListener(new UnityAction<string>(this.OnYScale));
		}

		// Token: 0x06000CD1 RID: 3281 RVA: 0x000676D8 File Offset: 0x000658D8
		private void PrepareDetailMapDropdown()
		{
			this.detailMapDropdown.options.Clear();
			this.detailMapDropdown.options.Add(new Dropdown.OptionData("Default"));
			this.detailMapDropdown.options.Add(new Dropdown.OptionData("None"));
			MaterialEditView componentInParent = base.GetComponentInParent<MaterialEditView>();
			foreach (Texture texture in componentInParent.DetailTextures)
			{
				Dropdown.OptionData item = new Dropdown.OptionData(texture.name);
				this.detailMapDropdown.options.Add(item);
			}
			this.detailMapDropdown.onValueChanged.AddListener(new UnityAction<int>(this.OnSelection));
		}

		// Token: 0x06000CD2 RID: 3282 RVA: 0x0006778C File Offset: 0x0006598C
		public override void ValidateOption(MaterialEntryGui newGui, List<MaterialEntryGui> newGuis)
		{
			base.ValidateOption(newGui, newGuis);
			if (this.selectedGui == null)
			{
				return;
			}
			bool flag = this.selectedGui.Wrapper.Material.HasProperty("_DetailNormalMap");
			base.gameObject.SetActive(flag);
			if (!flag)
			{
				return;
			}
			this.detailMapDropdown.value = this.selectedGui.Wrapper.DetailNormalMap;
			Vector2 textureScale = this.selectedGui.Wrapper.Material.GetTextureScale("_DetailAlbedoMap");
			this.xScale.text = textureScale.x.ToString();
			this.yScale.text = textureScale.y.ToString();
		}

		// Token: 0x06000CD3 RID: 3283 RVA: 0x00067854 File Offset: 0x00065A54
		private void OnSelection(int index)
		{
			if (this.selectedGuis == null)
			{
				return;
			}
			foreach (MaterialEntryGui materialEntryGui in this.selectedGuis)
			{
				materialEntryGui.Wrapper.SetDetailNormalMap(index);
			}
		}

		// Token: 0x06000CD4 RID: 3284 RVA: 0x000678C4 File Offset: 0x00065AC4
		private void OnXScale(string text)
		{
			if (this.selectedGuis == null)
			{
				return;
			}
			float x = float.Parse(text);
			foreach (MaterialEntryGui materialEntryGui in this.selectedGuis)
			{
				Vector2 textureScale = materialEntryGui.Wrapper.Material.GetTextureScale("_DetailAlbedoMap");
				materialEntryGui.Wrapper.Material.SetTextureScale("_DetailAlbedoMap", new Vector2(x, textureScale.y));
			}
		}

		// Token: 0x06000CD5 RID: 3285 RVA: 0x00067964 File Offset: 0x00065B64
		private void OnYScale(string text)
		{
			if (this.selectedGuis == null)
			{
				return;
			}
			float y = float.Parse(text);
			foreach (MaterialEntryGui materialEntryGui in this.selectedGuis)
			{
				Vector2 textureScale = materialEntryGui.Wrapper.Material.GetTextureScale("_DetailAlbedoMap");
				materialEntryGui.Wrapper.Material.SetTextureScale("_DetailAlbedoMap", new Vector2(textureScale.x, y));
			}
		}

		// Token: 0x040011D8 RID: 4568
		private const string DETAIL_TEXTURE = "_DetailAlbedoMap";

		// Token: 0x040011D9 RID: 4569
		private const string DETAIL_NORMAL_MAP = "_DetailNormalMap";

		// Token: 0x040011DA RID: 4570
		[SerializeField]
		[Header("Required References")]
		private Dropdown detailMapDropdown;

		// Token: 0x040011DB RID: 4571
		[SerializeField]
		private InputField xScale;

		// Token: 0x040011DC RID: 4572
		[SerializeField]
		private InputField yScale;
	}
}
